package vip.rssc.dynamic.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vip.rssc.dynamic.entity.TestUser;
import vip.rssc.dynamic.service.TestUserService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Description: [TestUserDynamicSlaveController]</p >
 * Created on 2020年10月25日
 *
 * @author <a href="1014376159@qq.com">CJ</a>
 * @version 1.0
 * Copyright (c) 2020 cj
 */


@RestController
@RequestMapping("dynamic-slave/user")
@Slf4j
public class TestUserSlaveController {


    @Resource(name = "dynamicTestUserServiceSlaveImpl")
    private TestUserService testUserDynamicService;

    /**
     * localhost:8080/dynamic-slave/user/save
     * {"name":"cj","age":4,"birthday":"2017-05-13","remark":""}
     *
     * @param testUserDynamic
     */


    @PostMapping("save")
    public void save(@RequestBody TestUser testUserDynamic) {
        testUserDynamicService.save(testUserDynamic);
    }

    /**
     * localhost:8080/dynamic-slave/user/update
     * {"name":"cj","age":2,"birthday":"2017-05-13","remark":""}
     *
     * @param testUserDynamic
     */


    @PostMapping("update")
    public void updateById(@RequestBody TestUser testUserDynamic) {
        testUserDynamicService.updateById(testUserDynamic);
    }

    /**
     * localhost:8080/dynamic-slave/user/get/1
     *
     * @param id
     * @return
     */


    @GetMapping("get/{id}")
    public TestUser selectById(@PathVariable("id") Long id) {
        return testUserDynamicService.getById(id);
    }

    /**
     * localhost:8080/dynamic-slave/user/select
     *
     * @return
     */


    @GetMapping("select")
    public List<TestUser> selectList() {
        return testUserDynamicService.list();
    }

    /**
     * localhost:8080/dynamic-slave/user/delete/1
     *
     * @param id
     */


    @PostMapping("delete/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        testUserDynamicService.removeById(id);
    }

}
